package com.wtgroup.demo.mianshi.流Stream;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author L&J
 * @version 0.0.0
 * @email liuhejun108@163.com
 * @date 2019/10/11 16:57
 */
public class DemoStream {

    @Test
    public void fun1(){

        List<String> list = Arrays.asList("a", "b", "c", "d", "e");

        // list.stream().forEach(( e ) -> {System.out.println(e); });

        List<String> collect = list.stream()
                .map(e -> {
                    return e + 1;
                })
                .map(e -> {
                    return e + 2;
                })
                .collect(Collectors.toList());
    }

    @Test
    public void fun2() {
        List<String> list = Arrays.asList("a", "b", "c", "d", "e");

        list.stream()
                .map(e -> {
                    return e + 1;
                })
                .forEach(e-> {
                    System.out.println();
                });
    }



    @Test
    public void funx() {
        List<String> myList =
                Arrays.asList("a1", "a2", "b1", "c2", "c1");

        myList
                .stream() // 创建流
                .filter(s -> s.startsWith("c")) // 执行过滤，过滤出以 c 为前缀的字符串
                .map(String::toUpperCase) // 转换成大写
                .sorted() // 排序
                .forEach(System.out::println); // for 循环打印

        // C1
        // C2
    }





}
